#include <Windows.h>
#include <iostream>
#include <iomanip>
#pragma comment(lib, "User32.lib")

std::string rgb2hex(int r, int g, int b, bool with_head = false);
std::string rgb2hex(int r, int g, int b, bool with_head)
{
    std::stringstream ss;
    if (with_head)
        ss << "#";
    ss << std::hex << (r << 16 | g << 8 | b);
    return ss.str();
}
//gcc .\colorT.cpp -o .\colorT.exe -lgdi32
int main(int argc, char const *argv[])
{
    HWND hWnd = ::GetDesktopWindow();
    HDC hdc = ::GetDC(hWnd);
    COLORREF pixel = ::GetPixel(hdc, 150, 50);
    int red = GetRValue(pixel);
    int green = GetGValue(pixel);
    int blue = GetBValue(pixel);
    std::cout << "start" << std::endl;
    std::cout << red << std::endl;
    std::cout << green << std::endl;
    std::cout << blue << std::endl;

    std::string hex = rgb2hex(red, green, blue);
    std::cout << "start" << std::endl;
    std::cout << "Hex: #" << hex << std::endl;
    return 0;
}
